﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using com.iss.inventory.Entity;
using com.iss.inventory.CustomModels;
using com.iss.inventory.Controllers;
using System.Windows.Forms;
using System.Web.UI.HtmlControls;
using System.Collections;

namespace Staionery_Inventory.Presentation.Disbursement
{
    public partial class DisbursementList : System.Web.UI.Page
    {
        InvManagementEntities ime; SRFDetail srfDetails; DispartmentController dc;
        StationeryRetrievalController src;//using StationeryRetrievalController
       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["empID"] == null)
            {
                Response.Redirect("~/Presentation/login.aspx");
            }

            srfDetails = new SRFDetail();
            dc = new DispartmentController();
            src = new StationeryRetrievalController();
            ime = new InvManagementEntities();
      

            //
                if (!IsPostBack)
                {
                    List<SRFDetail> showDetail = new List<SRFDetail>();
                    System.Web.UI.WebControls.Label lbl = this.Master.FindControl("lblLogInName") as System.Web.UI.WebControls.Label;
                    if (lbl != null)
                    {
                        lbl.Text = Session["UserName"].ToString();
                        int srfId = 0; string department = null; int departmentID = 0;
                         if (Request.QueryString["department"] == null)
                         {
                             department = (string)Session["Department"];
                             departmentID = (from s in ime.Departments where s.DeptName.Contains(department) select s.DeptID).First();
                             srfId = dc.getlast(departmentID);
                         }
                         else
                         {
                             department = Request.QueryString["department"].ToString();
                             departmentID = (from s in ime.Departments where s.DeptName.Contains(department) select s.DeptID).First();
                             srfId = Convert.ToInt32(Request.QueryString["strID"]);
                         }

                            
                            
                          
                           lblFormNo.Text = srfId.ToString();
                         lblDepartment.Text = department;
                         lblCollectionPoint.Text = (from s in ime.Departments where s.DeptID==departmentID select s.CollectionPoint).First().ToString();
                         DateTime dt = Convert.ToDateTime((from s in ime.SRFDetails where s.DeptID==departmentID && s.SRFID==srfId select s.CollectionDateTime).First());
                         lblCollectionDate.Text = dt.Date.ToShortDateString();
                         lblTimeOfCollection.Text = dt.ToString("hh:mm:ss");
                        var i = dc.getDispartment(srfId,departmentID);
                        gvItemsCollection.DataSource = i;
                        gvItemsCollection.DataBind();
                    }

                }
            }

        protected void btnPrint_Click(object sender, EventArgs e)
        {
           // HtmlGenericControl NewControl = new HtmlGenericControl("div");

           // // Set the properties of the new HtmlGenericControl control.
           //ArrayList arr=new ArrayList();
           //   divprint.Controls.CopyTo(arr, 0);
           //       Session["print"] =arry;
             Response.Redirect("~/Presentation/Disbursement/print.aspx");
            // Here ControlContainer is the ID of the asp:PlaceHol
        }
    }
}